<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>算式题页面</title>
	</head>
	<body>
		
			<input type="text"   id="div1" value="" />
			<select  id="div2" >
				<option value="+"  >+</option>
				<option value="-"  >-</option>
				<option value="*"  >*</option>
				<option value="%"  >%</option>
			</select>
			<input type="text"  id="div3" value="" />
			<button type="submit" id="num">计算</button>
			<input type="text"  id="div4" value="" />
	</body>
	<script type="text/javascript">
		function adds()
		{
			var firsttext = document.getElementById('div1').value;
			var secondtext =document.getElementById('div3').value;
			var resulttext =parseFloat(firsttext)+parseFloat(secondtext);
			document.getElementById('div4').value =resulttext;
		}
		function deletes()
		{
			var firsttext = document.getElementById('div1').value;
			var secondtext =document.getElementById('div3').value;
			var resulttext =parseFloat(firsttext)-parseFloat(secondtext);
			document.getElementById('div4').value =resulttext;
		}
		function mls()
		{
			var firsttext = document.getElementById('div1').value;
			var secondtext =document.getElementById('div3').value;
			var resulttext =parseFloat(firsttext)*parseFloat(secondtext);
			document.getElementById('div4').value =resulttext;
		}
		
		function chus()
		{
			var firsttext = document.getElementById('div1').value;
			var secondtext =document.getElementById('div3').value;
			var resulttext =parseFloat(firsttext)%parseFloat(secondtext);
			document.getElementById('div4').value =resulttext;
		}
	
	
		function equation()
		{
			//获取加减乘除
			var equ1=document.getElementById('div2');
			console.log(equ1);
			//获取选线中加减乘除的标识符
			var index =equ1.selectedIndex;
			console.log(index);
			//获得option里的的值
			var equ2 = equ1.options[index].value;
			console.log(equ2);
			
			switch (equ2){
				case '+':
					adds();
					console.log('+');
					break;
				case '-':
					deletes();
					console.log('-');
					break;
				case '*':
					mls();
					console.log('*');
					break;
				case '%':
					chus();
					console.log('%');
					break;
				default:
					break;
			}	
		}
		document.getElementById('num').onclick =equation;
	</script>
</html>
